package com.jagochan.mall.controller;


import com.jagochan.mall.common.result.ApiResult;
import com.jagochan.mall.domain.po.Category;
import com.jagochan.mall.domain.vo.CategoryTreeVO;
import com.jagochan.mall.domain.vo.req.CategoryReq;
import com.jagochan.mall.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "分类")
@RequiredArgsConstructor
@RestController
@RequestMapping("/category")
public class CategoryController {

    private final CategoryService categoryService;

    @GetMapping("/tree-list")
    @ApiOperation("返回树状结构的分类")
    public ApiResult<List<CategoryTreeVO>> listCategoryTreeVO() {
        return ApiResult.success(categoryService.listCategoryTreeVO());
    }

    @PostMapping("/save")
    @ApiOperation("新增分类")
    public ApiResult<String> saveCategory(@RequestBody CategoryReq categoryReq) {
        return ApiResult.success(categoryService.saveCategory(categoryReq));
    }

}
